package com.itany.corejava.code07_面向对象.bms;

/**
 * @author: 石小俊
 * @date: 2023年03月09日 17:10
 * @version: 1.0
 */
public class LoanSavingAccount extends SavingAccount implements Loanable {

    // 贷款总额
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void provideLoan(double money) {
        // 当前贷款总额 = 原有的贷款总额+当前贷款的金额
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 对于存续贷款账户
        // 账户余额大于等于还贷金额,才可以还贷
        if(getBalance() >= money){
            // 当前账户余额减少money
            setBalance(getBalance() - money);
            // 贷款总额减少money
            loanAmount -= money;
            return true;
        }
        // 否则还贷失败
        return false;
    }

    @Override
    public double queryLoan() {
        return this.loanAmount;
    }
}
